<?php
/**
 * @package Autogenerator for Joomla!
 * @version 3.0.0
 * @author Truong Cong Duc <truongcongduc4@gmail.com>
 * @link autogenerator.blogspot.com
 * @copyright (c) 2013, Truong Cong Duc
 * @license GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

JFormHelper::loadFieldClass('list');

class JFormFieldComponent extends JFormFieldList
{

    public $type = 'Component';

    protected function getOptions()
    {
        $aOptions = array();

        $oDatabase = JFactory::getDbo();
        $oQuery = $oDatabase->getQuery(true);

        $oQuery->select('component.id AS value, component.title AS text')
                ->from('#__auto_component AS component')
                ->where('component.status = 1')
                ->order('component.title ASC');

        $oDatabase->setQuery($oQuery);

        try
        {
            $aOptions = $oDatabase->loadObjectList();
        }
        catch (RuntimeException $oException)
        {
            JError::raiseWarning(500, $oException->getMessage());
        }
        
        $oParent = new stdClass;
        $oParent->text = JText::_('JGLOBAL_ROOT_PARENT');
        $oParent->value = '';
        
        array_unshift($aOptions, $oParent);

        return $aOptions;
    }

}
